package com.sharepics.utils.bean;

import org.springframework.util.StringUtils;

import com.google.appengine.api.blobstore.BlobKey;
import com.sharepics.bean.Album;
import com.sharepics.bean.Picture;
import com.sharepics.bean.XMLAlbum;
import com.sharepics.bean.XMLPicture;

public class BeanUtils {

	public static Album get(XMLAlbum xmlAlbum){
		Album a = new Album();
		a.id = xmlAlbum.getId();
		a.name = xmlAlbum.getName();
		return a;
	}
	
	public static XMLAlbum get(Album album){
		XMLAlbum xmlAlbum = new XMLAlbum();
		xmlAlbum.setId(album.id);
		xmlAlbum.setName(album.name);
		return xmlAlbum;
	}
	
	public static Picture get(XMLPicture xmlPicture){
		Picture pic = new Picture();
		pic.id = xmlPicture.getId();
		pic.name = xmlPicture.getName();
		pic.latitude = xmlPicture.getLatitude();
		pic.longitude = xmlPicture.getLongitude();
		pic.date = xmlPicture.getDate();
		pic.contentType = xmlPicture.getContentType();
		if(xmlPicture.getBlobKey() != null && !xmlPicture.getBlobKey().trim().equals("")){
			pic.blob = new BlobKey(xmlPicture.getBlobKey());
		}
		
		return pic;
	}
	
	public static XMLPicture get(Picture pic){
		XMLPicture xmlPic = new XMLPicture();
		xmlPic.setId(pic.id);
		xmlPic.setName(pic.name);
		xmlPic.setLatitude(pic.latitude);
		xmlPic.setLongitude(pic.longitude);
		xmlPic.setContentType(pic.getContentType());
		xmlPic.setBlobKey(pic.getBlob().getKeyString());
		return xmlPic;
	}
	
}
